/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package servlets;

import bdd.beans.Ec;
import bdd.beans.Enseignant;
import bdd.beans.Type;
import bdd.beans.Jnttypeecenseignant;
import bdddaos.DAOJnttypeecenseignant;
import bdddaos.DAOType;
import bdddaosimpl.DAOEcImpl;
import bdddaosimpl.DAOEnseignantImpl;
import bdddaosimpl.DAOJnttypeecenseignantImpl;
import bdddaosimpl.DAOTypeImpl;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author jubarre
 */
public class ListesTypeEcServlet extends HttpServlet {
  

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        
    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        int num_enseignant;
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String url = request.getRealPath("WEB-INF/prop.properties");
        out.println("DANS DOGET");

        num_enseignant = Integer.parseInt(request.getParameter("numero_enseignant"));
        request.setAttribute("numeroEnseignant", num_enseignant);

        DAOEnseignantImpl dao = new DAOEnseignantImpl();
        List<Enseignant> l = dao.findByEnseignantPoste();
        request.setAttribute("listeEnseignants", l);

        DAOEnseignantImpl uneDao=new DAOEnseignantImpl();
        Enseignant unEns=uneDao.find(num_enseignant);
        Set<Jnttypeecenseignant> listeJnt= unEns.getJnttypeecenseignants();
        request.setAttribute("listeJnt", listeJnt);
        

        DAOTypeImpl daoType = new DAOTypeImpl();
        List<Type> listeTypes = daoType.findAll();
        request.setAttribute("listeTypes", listeTypes);
        /*ListeTypes listeTypes = new ListeTypes();
        listeTypes.recupererListeTypes();
        request.setAttribute("listeTypes", listeTypes.getListeTypes());*/

        DAOEcImpl daoEc = new DAOEcImpl();
        List<Ec> listeEC = daoEc.findAll();
        //ListeEC listeEC = new ListeEC();
        //listeEC.recupererListeEC();
        request.setAttribute("listeEC", listeEC);

        Integer a = 1;
        request.setAttribute("number", a);
        // On re-route l'appel vers la page d'accueil JSP
        gotoPage("/gestion_ec.jsp", request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

    private void gotoPage(String adress, HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(adress);
    dispatcher.forward(request,response);
  }

}
